package com.un.web.topic.controller;

import cn.hutool.db.Page;
import com.github.pagehelper.PageInfo;
import com.un.core.common.R;
import com.un.core.utils.TokenUtils;
import com.un.web.topic.domian.entity.TopicAudit;
import com.un.web.topic.domian.vo.TopicComVO;
import com.un.web.topic.service.TopicAuditService;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * (topic_audit)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/topic_audit")
public class TopicAuditController {
    /**
     * 服务对象
     */
    @Autowired
    private TopicAuditService topicAuditService;


    @GetMapping("listPage")
    public R getAll(Page page){
        PageInfo<TopicAudit> list = topicAuditService.selectAllByPage(page);
        return R.success(list);
    }

    @PostMapping("save")
    public R addAudit(@RequestBody TopicAudit topicAudit){
        topicAudit.setCreateUserId(TokenUtils.getUserId());
        topicAuditService.saveOrUpdate(topicAudit);
        return R.success();
    }

    @GetMapping("check")
    public R checkTopic(String keyword,String type){
        List<TopicComVO> topicVOList = topicAuditService.getLikeTopicList(keyword, type);
        return R.success(topicVOList);
    }

}
